package com.lwm.jdbc.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 * 抽取DAO重复的jdbcTemplate
 * Spring 官方已经提供相应的类 --->适用于XML
 *
 * @author liweimin
 * @date 2021/6/11 15:06
 * @since
 */
public class JdbcDAOSupport {
    private JdbcDaoSupport jdbcDaoSupport;

    private JdbcTemplate jdbcTemplate;
    private DriverManagerDataSource dataSource;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public DriverManagerDataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DriverManagerDataSource dataSource) {
        if (jdbcTemplate == null) {
            jdbcTemplate = new JdbcTemplate(dataSource);
        }
    }
}
